package guda.house.biz.impl;

import java.util.List;

import guda.house.biz.query.AccountEstateQuery;
import guda.house.biz.query.BuildingQuery;
import guda.house.biz.query.SuiteQuery;
import guda.house.biz.query.UnitQuery;
import guda.house.biz.util.Transform;
import guda.house.biz.util.TransformHelper;
import guda.house.dal.dao.*;
import guda.house.dal.dataobject.BuildingDO;
import guda.house.dal.dataobject.SuiteDO;
import guda.house.dal.dataobject.UnitDO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import guda.house.biz.AccountEstateBiz;
import guda.house.dal.dataobject.AccountEstateDO;
import guda.grape.autogen.common.page.BaseQuery;
import guda.grape.autogen.common.page.BizResult;

public class AccountEstateBizImpl implements AccountEstateBiz{

    private final static Logger logger = LoggerFactory.getLogger(AccountEstateBizImpl.class);

    @Autowired
    private AccountEstateDAO accountEstateDAO;
    @Autowired
    private BuildingDAO buildingDAO;
    @Autowired
    private UnitDAO unitDAO;
    @Autowired
    private SuiteDAO suiteDAO;
    @Autowired
    private BillPayDAO billPayDAO;
    @Autowired
    private VillageDAO villageDAO;

    public BizResult detail(long id) {
        BizResult bizResult = new BizResult();
        try{
            AccountEstateDO accountEstateDO = accountEstateDAO.getAccountEstateById(id);
            bizResult.data.put("accountEstateDO", accountEstateDO);
            bizResult.success = true;
        }catch(Exception e){
            logger.error("query AccountEstate error",e);
        }
        return bizResult;
}

    public BizResult list(AccountEstateQuery accountEstateQuery) {
        BizResult bizResult = new BizResult();
        try {

            int totalCount = accountEstateDAO.countForPage(accountEstateQuery);
            accountEstateQuery.setTotalCount(totalCount);
            List<AccountEstateDO> accountEstateList = accountEstateDAO.selectForPage(accountEstateQuery);
            bizResult.data.put("accountEstateList", accountEstateList);
            bizResult.data.put("query", accountEstateQuery);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("view AccountEstate list error", e);
        }
            return bizResult;
     }

    public BizResult delete(long id) {
        BizResult bizResult = new BizResult();
        try {
            accountEstateDAO.delAccountEstateById(id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("delete accountEstate error", e);
        }
        return bizResult;
    }

    public BizResult create(AccountEstateDO accountEstateDO) {
        BizResult bizResult = new BizResult();
        try {
            long id = accountEstateDAO.insert(accountEstateDO);
            bizResult.data.put("id", id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("create AccountEstate error", e);
        }
        return bizResult;
    }

    @Override
    public BizResult update(AccountEstateDO accountEstateDO) {
        BizResult bizResult = new BizResult();
        try {
            accountEstateDAO.updateByIdSelective(accountEstateDO);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("update AccountEstate error", e);
        }
        return bizResult;
    }


}
